/**
 * Copyright (c) 2011 Nokia Corporation.
 */

// Qt includes
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QObject>

#ifdef Q_OS_SYMBIAN
    // Symbian specific includes
    #include <aknappui.h>
#endif

// Backup2Go includes
#include "backupengine.h"
#include "drivemodel.h"
#include "filemodel.h"
#include "haptics.h"
#include "trace.h"


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

#ifdef Q_OS_SYMBIAN
    // Lock to portrait.
    CAknAppUi* appUi = dynamic_cast<CAknAppUi*>( CEikonEnv::Static()->AppUi() );
    TRAP_IGNORE( appUi->SetOrientationL( CAknAppUi::EAppUiOrientationPortrait ); );
#endif

    QDeclarativeView view;
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    
    Haptics haptics;
    BackupEngine backupEngine;

    FileModel *sourceFileModel =
        qobject_cast<FileModel*>(backupEngine.sourceFileModel());
    DriveModel *driveModel =
        qobject_cast<DriveModel*>(backupEngine.driveModel());

    if (sourceFileModel) {
        DEBUG_INFO(sourceFileModel->rowCount());
    }

    if (driveModel) {
        DEBUG_INFO(driveModel->rowCount() << "drives available.");
    }

    QDeclarativeEngine* engine = view.engine();
    engine->rootContext()->setContextProperty("haptics", &haptics);
    engine->rootContext()->setContextProperty("engine", &backupEngine);
    engine->rootContext()->setContextProperty("sourceFileModel", sourceFileModel);
    engine->rootContext()->setContextProperty("driveModel", driveModel);

    QObject::connect(engine, SIGNAL(quit()), &app, SLOT(quit()));

    view.setSource(QUrl("qrc:/main.qml"));

#if defined(Q_OS_SYMBIAN)
    view.setAttribute(Qt::WA_NoSystemBackground);
    view.showFullScreen();
#elif defined(Q_WS_SIMULATOR)
    DEBUG_INFO("Running in simulator.");
    view.showMaximized();
#else
    DEBUG_INFO("Running in desktop environment?");
    view.show();
#endif

    return app.exec();
}

// End of file.
